package com.hbk.codemaker;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.util.List;

import javax.swing.JPanel;

import com.hbk.programe.Method;

public class MethodsPanel extends JPanel{
	
	public static final int MIN_HEIGHT=20;
	
	private int width=1024;
	
	private MainFrame window;
	
	public MethodsPanel(int width,MainFrame frame) {
		this.width=width;
		this.window=frame;
		setLayout(new FlowLayout(FlowLayout.LEFT, 0, 5));
	}
	
	public void addMethod() {
		MethodPanel panel=new MethodPanel(width,window);
		add(panel);
	}
	
	public void setMethods(List<Method> methods) {
		removeAll();
		for (Method field : methods) {
			MethodPanel panel=new MethodPanel(width,window);
			panel.setMethod(field);
			add(panel);
		}
		repaint(width);
	}
	
	public void repaint(int width) {
		this.width=width;
		int count=getComponentCount();
		setPreferredSize(new Dimension(width, (MethodPanel.METHOD_HEIGHT*count)+MIN_HEIGHT));
		repaint();
		
		for(int i=0;i<count;i++) {
			((MethodPanel)getComponent(i)).repaint(width);;
		}
	}

}
